package com.aaa.tars.controller;

import com.aaa.tars.entity.guideImages;
import com.aaa.tars.service.GuideImagesService;
import com.aaa.tars.service.impl.GuideImagesServiceImpl;
import com.aaa.tars.util.Page;
import com.aaa.tars.util.Result;
import com.aaa.tars.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

/**
 * @FileName: GuideImagesController
 * @Description: 攻略图片控制器
 * @Author: 李宗盛
 * @CreateTime: 2025/9/17 20:10
 * @Version: 17
 */
@RestController
@RequestMapping("guideImages")
public class GuideImagesController {
    @Autowired
    private GuideImagesService guideImagesService;
    
    @PostMapping("queryByPage")
    public Result queryByPage(@RequestBody Page<guideImages> page){
        return ResultUtil.success(guideImagesService.queryByPage(page));
    }
    
    @GetMapping("queryById")
    public Result queryById(Integer imageId){
        return ResultUtil.success(guideImagesService.queryById(imageId));
    }
    
    @PostMapping("add")
    public Result add(@RequestBody guideImages guideImages){
        // 设置上传时间为当前时间
        guideImages.setUploadTime(new Date());
        return ResultUtil.success(guideImagesService.add(guideImages));
    }
    
    @PutMapping("update")
    public Result update(@RequestBody guideImages guideImages){
        return ResultUtil.success(guideImagesService.update(guideImages));
    }
    
    @DeleteMapping("deleteById")
    public Result deleteById(Integer imageId){
        return ResultUtil.success(guideImagesService.deleteById(imageId));
    }
    
    /**
     * 上传攻略图片
     * @param file
     * @return
     */
    @PostMapping("/uploadImage")
    public Result uploadImage(@RequestParam("file") MultipartFile file) {
        return guideImagesService.uploadImage(file);
    }

    /**
     * 批量上传攻略图片
     * @param files
     * @return
     */
    @PostMapping("/uploadImages")
    public Result uploadImages(@RequestParam("files") MultipartFile[] files) {
        // 这里需要修改service接口和实现类来支持批量上传
        return ((GuideImagesServiceImpl) guideImagesService).uploadImages(files);
    }
}